# loop over analysis combinations  
for(OUTER_ in OUTER_ITERATION_SEQUENCE){

    # get entry + name entries
    entry_ <- my_grid[OUTER_,]
    for(entry_name_ in names(entry_)){ eval(parse(text = sprintf("%s = entry_$%s",entry_name_,entry_name_))) }
    algorithm_i <- as.character( algorithm_i )
    distanceMeasure_i <- as.character( distanceMeasure_i )

    # process example data 
    source("./Analysis/LinkOrgs_ProcessExampleData.R")

    # Main analysis sequence
    {
      LinkOrgs::print2( c(exampleNum_i, algorithm_i) )
      LinkOrgs::print2( tail(log(sort( sapply(ls(),function(x){object.size(get(x))})) )) )

      # set acceptance parameters
      maxDist <- maxDist_network <- NULL
      AveMatchNumberPerAlias <- 5.
      AveMatchNumberPerAlias_network <- 1.5
      
      # turn off cuda for deezy match 
      if(algorithm_i == "DeezyMatch"){ Sys.setenv(CUDA_VISIBLE_DEVICES="") }
      
      # main analysis run 
      LinkOrgs::print2(as.character(c(exampleNum_i, as.character(algorithm_i), as.character(distanceMeasure_i))))
      t0 <- Sys.time(); z_red_LinkOrgs <- try(LinkOrgs(
          x = x_red, by.x = by.x,
          y = y_red, by.y = by.y,
          ReturnProgress = T, ReturnDecomposition = F, ReturnDiagnostics = T,
          ToLower = T, NormalizeSpaces = T, RemovePunctuation = F,
          MaxDist = maxDist,
          algorithm = algorithm_i,
          ml_version = ml_version,
          MaxDist_network = maxDist_network,
          conda_env = CondaEnvToUse,
          DistanceMeasure = distanceMeasure_i, qgram = qgramMaster,
          AveMatchNumberPerAlias = AveMatchNumberPerAlias,
          AveMatchNumberPerAlias_network = AveMatchNumberPerAlias_network,
          nCores = nCoresUse,
          deezyLoc = deezyLoc),T)
      
      # open browser if LinkOrgs() fails 
      if("try-error" %in% class(z_red_LinkOrgs)){ browser() }

      # write LinkOrgs results 
      if(nrow(z_red_LinkOrgs) == 0){  z_red_LinkOrgs[1,] <- NA } 
      z_red_LinkOrgs$ExecutionTime <- as.numeric(Sys.time() - t0, units = "mins")
      data.table::fwrite(z_red_LinkOrgs,
                         file = sprintf("./Results/z_LinkOrgs_Ex%s_%s_%s.csv",exampleNum_i,algorithm_i,distanceMeasure_i))
      try(rm(directory_LinkIt, directory_trigrams, z_red_LinkOrgs), T)
    }
}# end OUTER_ in OUTER_ITERATION_SEQUENCE
